﻿<%@ Page Title="" Language="C#" MasterPageFile="~/SiteJN.Master" AutoEventWireup="true" CodeBehind="listwork.aspx.cs" Inherits="jnagr.Web.devinfo.listwork" %>

<%@ Register Src="~/Controls/checkright.ascx" TagPrefix="uc1" TagName="checkright" %>
<%@ Register Src="~/Controls/copyright.ascx" TagPrefix="uc1" TagName="copyright" %>
<%@ Register Src="~/Controls/devwork.ascx" TagPrefix="uc1" TagName="devwork" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script src="../js/testdata.js"></script>
    <script type="text/javascript">
        var sprovince = "";
        var scity = "";
        var scounty = "";
        var areas = "";
        var se = "";
        var sebm = "";
        var getdata = "";
        var level;
        var markerClusterer;
        var markers = [];
        var devid;
        var pt;
        var map;
        var data_info;
        var opts;
        var StartTime;
        var EndTime;
        var devtype = "";
        var i0 = new BMap.Icon('../images/map1.png', new BMap.Size(32, 32), { anchor: new BMap.Size(16, 32) });
        var i1 = new BMap.Icon('../images/map3.png', new BMap.Size(32, 32), { anchor: new BMap.Size(16, 32) });
        $(function () {
            $(".toptitle").attr("class", "stoptitle");
            var curr_time = new Date();
            var strDate = curr_time.getFullYear() + "-";
            strDate += curr_time.getMonth() + 1 + "-";
            strDate += curr_time.getDate();
            EndTime = strDate;
            devtype = getUrlParam("devtype");

            if (devtype == "PET") {
                curmenu('卵幼虫蛹');
            }
            else if (devtype == "GRA") {
                curmenu('草害');
            }
            else if (devtype == "RAT") {
                curmenu('鼠害');
            }
            else if (devtype == "SIC") {
                curmenu('病害');
            }
            $.ajax({
                type: "post",
                dataType: "json",
                url: "../admin/getinfo.ashx?action=level",
                success: function aa(data) {
                    sprovince = data[0].province;
                    scity = data[0].city;
                    scounty = data[0].county;
                    InitTree();
                    InitMap();
                    showxc();
                }
            });
        });

        function InitMapmark() {
            $('#win').datagrid({
                //title: '测报点列表', //表格标题
                url: '../devinfo/GetDays.ashx', //请求数据的页面
                sortName: 'devID', //排序字段
                idField: 'devID', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: '95%', //宽度
                height: '95%', //高度
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: true,
                singleSelect: true,
                method: 'post',
                columns: [[
	                { title: '测报站名', field: 'mname', width: 80, sortable: true }
                ]],
                toolbar: "#tab_toolbar",
                queryParams: { "action": "querywork", "devtype": devtype, "edate": EndTime },
                pageNumber: 1, //默认索引页
                pageSize: 500, //默认一页数据条数
                rownumbers: true, //行号
                pageList: [10, 20, 50, 200, 500],
                pagination: false, //是否开启分页                
                onLoadSuccess: function (data) {
                    data_info = [];
                    getdata = data;
                    showxc();
                    map.clearOverlays();
                    $.each(data.rows, function (k, v) {
                        data_info.push({ "lng": v["mjd"], "lat": v["mwd"], "mlevel": v["devok"], "mname": v["devname"], "devid": v["DevID"] });
                    });
                    var mlevel;
                    var marker;
                    var ptt = "";
                    if (markers.length > 0) {
                        if (markerClusterer != null) {
                            markerClusterer.removeMarkers(markers);
                            markerClusterer = null;
                        }
                        markers = [];
                    }
                    for (var i = 0; i < data_info.length; i++) {
                        mlevel = data_info[i].mlevel;
                        ptt = new BMap.Point(data_info[i].lng, data_info[i].lat);
                        if (mlevel == '1')
                            marker = new BMap.Marker(ptt, { icon: i1 });
                        else
                            marker = new BMap.Marker(ptt, { icon: i0 });
                        //var did = data_info[i].devid;
                        map.addOverlay(marker);
                        label = new BMap.Label(data_info[i].mname, { offset: new BMap.Size(20, -10) });
                        marker.setLabel(label);
                        markers.push(marker);
                        //addClickHandler(did, marker);
                    }
                    if (markers.length > 0)
                        markerClusterer = new BMapLib.MarkerClusterer(map, { markers: markers });//对地图扩大缩小后会都所有的点全显示出来。
                    if (scounty != "")
                        map.centerAndZoom(scounty, 12);
                    else if (scity != "")
                        map.centerAndZoom(scity, 10);
                    else if (sprovince != "")
                        map.centerAndZoom(sprovince, 8);
                    else
                        map.centerAndZoom("西安", 5);
                    if (areas != "")
                        getBoundary(areas);
                    //renderstation();
                }
            });

        }
        function InitTree() {
            $('#pt').tree({
                width: '100%', //宽度 
                lines: true,
                //data: provincetree,   
                url: '../areainfo/GetArea.ashx', //请求数据的页面 
                method: 'post',
                queryParams: { "action": "querymyareauser" },
                onBeforeExpand: function (node) {
                    $("#pt").tree("options").queryParams = { "action": "queryyb" };
                    $('#pt').tree('options').url = "../areainfo/GetArea.ashx?pid=" + node.id;
                },
                onClick: function (node) {
                    if (node.text != "") {
                        sebm = node.bm;
                        //获取地区全称
                        if (sebm == "0")
                            areas = "";
                        else if (sebm.length == 6 && sebm.indexOf("0000")) {
                            areas = node.text;
                        }
                        else {
                            var result = $.ajax({
                                url: "../areainfo/GetArea.ashx?action=queryarea",
                                type: 'post',
                                dataType: 'json',
                                async: false,
                                cache: false
                            }).responseText;
                            areas = result;
                        }
                        reloadgridTree();
                    }

                },
                onLoadSuccess: function (node, param) {

                }
            });
        }

        function InitGird() {
            $('#mtgrid').datagrid({
                toolbar: '#tab_toolbars',
                title: "数据列表",
                iconCls: 'icon icon-list',

                width: '100%',
                height: '100%',
                nowrap: true, //折行
                rownumbers: true, //行号
                striped: true, //隔行变色
                idField: 'DevID', //主键
                singleSelect: false, //单选
                selectOnCheck: true,
                checkOnSelect: true,
                columns: [[
                     { title: '设备名称', field: 'devname', width: 80, sortable: true },
                     { title: '设备编号', field: 'DevID', width: 80, sortable: true },
	                { title: '用户名', field: 'uname', width: 80, sortable: true },
                    {
                        title: '是否工作', field: 'devok', width: 80, formatter: function (value, row, index) {
                            if (value == "0")
                                return '<img src="/images/bullet_red.png" height="16" width="16"/>';
                            else
                                return '<img src="/images/bullet_green.png" height="16" width="16" />';
                        }
                    },
                    { title: '单位邮箱', field: 'uemail', width: 150 },
                    { title: '负责人姓名', field: 'utruename', width: 80 },
                    { title: '手机', field: 'uphone', width: 80 },
                    {
                        title: '提醒', field: 'u', width: 100, formatter: function (value, row, index) {
                            if (row.uid != "") {
                                return '<img src="../CSS/IconsExtension/phone.png" onclick="sendmsg(' + row.uphone + ')" /> <img src="../CSS/IconsExtension/email.png" onclick="sendmail(' + row.uid + ')" />';

                            }

                        }
                    }
                ]],
                pagination: true,
                pageSize: 20,
                pageList: [20, 40, 50]
            });
            $('#mtgrid').datagrid({
                data: getdata
            });


        }
        function getQueryParams(queryParams) {
            var StartTime = $("#StartTime").datebox("getValue");
            var EndTime = $("#EndTime").datebox("getValue");
            var utype = $("#utype").combobox("getValue");
            queryParams.sdate = StartTime;
            queryParams.edate = EndTime;
            queryParams.utype = utype;
            queryParams.devtype = devtype;
            return queryParams;

        }
        //增加查询参数，重新加载表格  
        function reloadgrid() {
            var queryParams = $('#mtgrid').datagrid('options').queryParams;
            getQueryParams(queryParams);
            $('#mtgrid').datagrid('options').queryParams = queryParams;
            $("#mtgrid").datagrid({
                url: '../devinfo/GetDays.ashx',
                queryParams: { "action": "querywork" }
            });

        }
        function showxc() {
            var curr_time = new Date();
            var tc_time = new Date(curr_time.getTime() + 24 * 60 * 60 * 1000);
            var strDate = curr_time.getFullYear() + "-";
            strDate += curr_time.getMonth() + 1 + "-";
            strDate += curr_time.getDate();
            var strDateend = tc_time.getFullYear() + "-";
            strDateend += tc_time.getMonth() + 1 + "-";
            strDateend += tc_time.getDate();
            $("#StartTime").datebox("setValue", strDate);
            $("#EndTime").datebox("setValue", strDateend);
            InitGird();

        }
        function sendmail(suid) {
            $.messager.confirm('提示', '你确定要发送信息吗？', function (r) {
                if (r) {
                    var date = $("#EndTime").datebox('getValue');
                    var msg = "您" + date + "的数据还没有上传请及时上传数据，以免耽误工作！";
                    var title = "上传数据提醒";
                    $('#fm').form('submit', {
                        url: "../info/getinfo.ashx?action=addp&title=" + title + "&uid=" + suid + "&infocontent=" + msg,
                        onSubmit: function () {
                            return $(this).form('validate');
                        },
                        success: function (result) {
                            if (result.indexOf("T") == 0) {
                                $.messager.alert("提示", "恭喜您，信息发送成功", "info");
                            }
                            else if ((result.indexOf("F") == 0)) {
                                $.messager.alert("提示", "发送失败，请重新操作！", "info");
                                return;
                            }
                            else if ((result.indexOf("L") == 0)) {
                                $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                                top.location = '/index.aspx';
                                return;
                            }
                        }
                    });
                }
            });

        }
        function sendmsg(suid) {
            $.messager.confirm('提示', '你确定要发送短信吗？', function (r) {
                if (r) {
                    var date = $("#EndTime").datebox('getValue');
                    var msg = "您" + date + "的数据还没有上传请及时上传数据，以免耽误工作！";
                    var title = "上传数据提醒";
                    $('#fm').form('submit', {
                        url: "../info/getinfo.ashx?action=addph&title=" + title + "&uid=" + suid + "&infocontent=" + msg,
                        onSubmit: function () {
                            return $(this).form('validate');
                        },
                        success: function (result) {
                            if (result.indexOf("T") == 0) {
                                $.messager.alert("提示", "恭喜您，信息发送成功", "info");
                            }
                            else {
                                $.messager.alert("提示", result, "info");
                                return;
                            }
                        }
                    });

                }
            })
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div id="mainDiv">
        <uc1:checkright runat="server" ID="checkright" />

        <uc1:devwork runat="server" id="devwork" />
        <div id="contentDiv">
            <div class="mypt">
                <ul id="pt"></ul>
            </div>
            <div id="mycontent">
                <div id="tab" class="easyui-tabs">
                    <div title="GSI" style="padding: 5px;">

                        <div style="position: relative;">
                            <div id="mymap"></div>
                            <div id="Maptype" style="height: 87px; width: 130px; position: absolute; float: left; margin-left: 850px; top: 50px; z-index: 99; color: Black; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px;">
                                <input id="CBstationname" onclick="ShowstationName('checkbox')" checked="checked" style="float: left; margin-left: 10px;"
                                    type="checkbox" />
                                <label onclick="ShowstationName('label')" style="height: 20px; width: 100px; float: left; text-align: left; font-size: 13px; font-family: 宋体; font-weight: bold; margin-top: 3px; cursor: pointer;">
                                    显示名称</label>
                            </div>
                        </div>

                    </div>
                    <div title="设备状态列表" style="overflow: auto; padding: 5px;">
                        <div id="mystations">
                            <div class="easyui-layout" data-options="fit:true">

                                <div data-options="region:'center'" style="padding: 5px; background: #eee;">

                                    <table id="mtgrid">
                                    </table>
                                    <div id="tab_toolbars" style="padding: 4px;">
                                        <table cellpadding="0" cellspacing="0" style="width: 100%">
                                            <tr>
                                                <td style="padding-left: 2px">

                                                    <div style="padding: 2px;">
                                                        时间从:  
           <input id="StartTime" class="easyui-datebox" style="width: 100px" />
                                                        到:  
           <input id="EndTime" class="easyui-datebox" style="width: 100px" />
                                                        工作状态：
                        <select id="utype" class="easyui-combobox" name="utype" style="width: 80px;">
                            <option value="2">全部</option>
                            <option value="0">未上传数据</option>
                            <option value="1">已上传数据</option>

                        </select>

                                                        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="reloadgrid()">查找</a>
                                                        <%--<a href="#" class="easyui-linkbutton" iconcls="icon-cancel">发送信息</a> --%>
                                                    </div>
                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div style="clear: both;"></div>
        </div>
        <uc1:copyright runat="server" ID="copyright" />
    </div>
    <form id="fm" method="post">
    </form>
</asp:Content>
